#define DAYSELECOR_DAY_POS_LEFT 1
#define DAYSELECOR_DAY_POS_RIGHT 2
#define DAYSELECOR_DAY_POS_MIDDLE 3
#define DAYSELECOR_DAY_TYPE_WEEKDAY 1
#define DAYSELECOR_DAY_TYPE_WEEKEND_DEFAULT 2
#define DAYSELECOR_DAY_TYPE_WEEKEND_STYLE1 3
#define DAYSELECOR_DAY_STATE_DEFAULT 1
#define DAYSELECOR_DAY_STATE_PRESSED 2
#define DAYSELECOR_DAY_STATE_SELECTED 3

#define DAYSELECTOR_DAY(_pos, _after)\
   alias: "day"#_pos "elm.swallow.day"#_pos; \
   part { name: "elm.swallow.day"#_pos; type: SWALLOW;\
      scale: 1;\
      clip_to: "clipper";\
      description { state: "default" 0.0;\
         visible: 0;\
         min: 0 0;\
         align: 0.0 0.5;\
         fixed: 1 0;\
         rel1 {\
            relative: 1.0 0.0;\
            to: "elm.swallow.day"#_after;\
            offset: 0 0;\
         }\
         rel2 {\
            relative: 1.0 1.0;\
            to: "elm.swallow.day"#_after;\
         }\
      }\
      description { state: "visible" 0.0;\
         inherit: "default" 0.0;\
         visible: 1;\
         min: 48 32;\
      }\
   }\
   programs{\
      program { signal: "elm,day"#_pos",visible"; source: "elm";\
         action: STATE_SET "visible" 0.0;\
         target: "elm.swallow.day"#_pos;\
      }\
      program { signal: "elm,day"#_pos",default"; source: "elm";\
         action: STATE_SET "default" 0.0;\
         target: "elm.swallow.day"#_pos;\
      }\
   }

group { name: "elm/dayselector/base/default";
   parts {
      part { name: "elm.swallow.day0"; type: SWALLOW;
         scale: 1;
         clip_to: "clipper";
         description { state: "default" 0.0;
            visible: 0;
            align: 0.0 0.5;
            fixed: 1 0;
            rel2.relative: 0.0 1.0;
         }
         description { state: "visible" 0.0;
            inherit: "default" 0.0;
            visible: 1;
            min: 48 32;
         }
      }
      DAYSELECTOR_DAY(1, 0)
      DAYSELECTOR_DAY(2, 1)
      DAYSELECTOR_DAY(3, 2)
      DAYSELECTOR_DAY(4, 3)
      DAYSELECTOR_DAY(5, 4)
      DAYSELECTOR_DAY(6, 5)
      part { name: "clipper"; type: RECT;
         description { state: "default" 0.0;
            rel1.to: "elm.swallow.day0";
            rel2.to: "elm.swallow.day6";
         }
         description { state: "disabled" 0.0;
            inherit: "default" 0.0;
            color: 255 255 255 128; // no cc
         }
      }
      part { name: "disabler"; type: RECT;
         description { state: "default" 0.0;
            color: 0 0 0 0; // no cc
            visible: 0;
         }
         description { state: "disabled" 0.0;
            inherit: "default" 0.0;
            visible: 1;
         }
      }
   }
   programs {
      program { signal: "elm,state,disabled"; source: "elm";
         action: STATE_SET "disabled" 0.0;
         target: "disabler";
         target: "clipper";
      }
      program { signal: "elm,state,enabled"; source: "elm";
         action: STATE_SET "default" 0.0;
         target: "disabler";
         target: "clipper";
      }
      program { signal: "elm,day0,visible"; source: "elm";
         action: STATE_SET "visible" 0.0;
         target: "elm.swallow.day0";
      }
      program { signal: "elm,day0,default"; source: "elm";
         action: STATE_SET "default" 0.0;
         target: "elm.swallow.day0";
      }
   }
}

group { name: "elm/check/base/dayselector/default";
   script {
      public check_pos; // Left, Right, Middle.
      public check_type; // Weekday, Weekend.
      public check_state = DAYSELECOR_DAY_STATE_DEFAULT; // Default, Pressed, Selected.

      public check_bg_show() {
         if (get_int(check_pos) == DAYSELECOR_DAY_POS_LEFT) {
           if (get_int(check_state) == DAYSELECOR_DAY_STATE_DEFAULT)
             set_state(PART:"bg", "default_left", 0.0);
           else if (get_int(check_state) == DAYSELECOR_DAY_STATE_PRESSED)
             set_state(PART:"bg", "pressed_left", 0.0);
           else if (get_int(check_state) == DAYSELECOR_DAY_STATE_SELECTED)
             set_state(PART:"bg", "selected_left", 0.0);
         } else if (get_int(check_pos) == DAYSELECOR_DAY_POS_RIGHT) {
           if (get_int(check_state) == DAYSELECOR_DAY_STATE_DEFAULT)
             set_state(PART:"bg", "default_right", 0.0);
           else if (get_int(check_state) == DAYSELECOR_DAY_STATE_PRESSED)
             set_state(PART:"bg", "pressed_right", 0.0);
           else if (get_int(check_state) == DAYSELECOR_DAY_STATE_SELECTED)
             set_state(PART:"bg", "selected_right", 0.0);
         } else if (get_int(check_pos) == DAYSELECOR_DAY_POS_MIDDLE) {
           if (get_int(check_state) == DAYSELECOR_DAY_STATE_DEFAULT)
             set_state(PART:"bg", "default_middle", 0.0);
           else if (get_int(check_state) == DAYSELECOR_DAY_STATE_PRESSED)
             set_state(PART:"bg", "pressed_middle", 0.0);
           else if (get_int(check_state) == DAYSELECOR_DAY_STATE_SELECTED)
             set_state(PART:"bg", "selected_middle", 0.0);
         }
      }
      public check_text_show() {
        if (get_int(check_state) == DAYSELECOR_DAY_STATE_SELECTED) {
          set_state(PART:"elm.text", "selected", 0.0);
        } else {
          if (get_int(check_type) == DAYSELECOR_DAY_TYPE_WEEKDAY) {
            set_state(PART:"elm.text", "default", 0.0);
          } else if (get_int(check_type) ==
                     DAYSELECOR_DAY_TYPE_WEEKEND_DEFAULT) {
            set_state(PART:"elm.text", "weekend_default", 0.0);
          }
          else if (get_int(check_type) == DAYSELECOR_DAY_TYPE_WEEKEND_STYLE1) {
            set_state(PART:"elm.text", "weekend_style1", 0.0);
          }
        }
      }
      public check_text_pressed() {
        set_state(PART:"elm.text", "pressed", 0.0);
      }
   }
   parts {
      part { name: "bg"; type: RECT;
         mouse_events: 0;
         description { state: "default" 0.0;
            color_class: "/bg-alt/normal/dayselector";
         }
         /* default */
         description { state: "default_left" 0.0;
            inherit: "default" 0.0;
         }
         description { state: "default_right" 0.0;
            inherit: "default" 0.0;
         }
         description { state: "default_middle" 0.0;
            inherit: "default" 0.0;
         }
         /* pressed */
         description { state: "pressed_left" 0.0;
            inherit: "default" 0.0;
            color_class: "/bg/selected/dayselector";
         }
         description { state: "pressed_right" 0.0;
            inherit: "default" 0.0;
            color_class: "/bg/selected/dayselector";
         }
         description { state: "pressed_middle" 0.0;
            inherit: "default" 0.0;
            color_class: "/bg/selected/dayselector";
         }
         /* selected */
         description { state: "selected_left" 0.0;
            inherit: "default" 0.0;
            color_class: "/bg/selected/dayselector";
         }
         description { state: "selected_right" 0.0;
            inherit: "default" 0.0;
            color_class: "/bg/selected/dayselector";
         }
         description { state: "selected_middle" 0.0;
            inherit: "default" 0.0;
            color_class: "/bg/selected/dayselector";
         }
      }
      part { name: "elm.text"; type: TEXT;
         mouse_events: 0;
         scale: 1;
         description { state: "default" 0.0;
            color_class: "/fg/normal/dayselector";
            rel1.offset: 4 4;
            rel2.offset: -5 -5;
            offscale;
            text {
               font: FN;
               size: 10;
               min: 1 1;
               ellipsis: -1;
               text_class: "button";
            }
         }
         description { state: "weekend_default" 0.0;
            inherit: "default" 0.0;
            color_class: "/fg/normal/dayselector/weekend";
         }
         description { state: "weekend_style1" 0.0;
            inherit: "default" 0.0;
            color_class: "/fg/normal/dayselector/weekend";
         }
         description { state: "selected" 0.0;
            inherit: "default" 0.0;
            color_class: "/fg/selected/dayselector";
         }
         description { state: "pressed" 0.0;
            inherit: "default" 0.0;
            color_class: "/fg/pressed/dayselector";
         }
      }
      part { name: "events"; type: RECT;
         ignore_flags: ON_HOLD;
         description { state: "default" 0.0;
            color: 0 0 0 0; // no cc
         }
      }
   }
   programs {
      program { signal: "mouse,down,1"; source: "events";
         script {
            set_int(check_state, DAYSELECOR_DAY_STATE_PRESSED);
            check_bg_show();
            check_text_pressed();
         }
      }
      program { signal: "mouse,up,1"; source: "events";
         script {
            set_int(check_state, DAYSELECOR_DAY_STATE_DEFAULT);
            check_bg_show();
            check_text_show();
         }
      }
      program { signal: "mouse,clicked,1"; source: "events";
         action: SIGNAL_EMIT "elm,action,check,toggle" "elm";
      }
      program { signal: "elm,state,check,on"; source: "elm";
         script {
            set_int(check_state, DAYSELECOR_DAY_STATE_SELECTED);
            check_bg_show();
            check_text_show();
         }
      }
      program { signal: "elm,state,check,off"; source: "elm";
         script {
            set_int(check_state, DAYSELECOR_DAY_STATE_DEFAULT);
            check_bg_show();
            check_text_show();
         }
      }
      program { signal: "elm,pos,check,left"; source: "elm";
         script {
            set_int(check_pos, DAYSELECOR_DAY_POS_LEFT);
            check_bg_show();
         }
      }
      program { signal: "elm,pos,check,right"; source: "elm";
         script {
            set_int(check_pos, DAYSELECOR_DAY_POS_RIGHT);
            check_bg_show();
         }
      }
      program { signal: "elm,pos,check,middle"; source: "elm";
         script {
            set_int(check_pos, DAYSELECOR_DAY_POS_MIDDLE);
            check_bg_show();
         }
      }
      program { signal: "elm,type,weekday,default"; source: "elm";
         script {
            set_int(check_type, DAYSELECOR_DAY_TYPE_WEEKDAY);
            check_text_show();
         }
      }
      program { signal: "elm,type,weekend,default"; source: "elm";
         script {
            set_int(check_type, DAYSELECOR_DAY_TYPE_WEEKEND_DEFAULT);
            check_text_show();
         }
      }
      program { signal: "elm,type,weekend,style1"; source: "elm";
         script {
            set_int(check_type, DAYSELECOR_DAY_TYPE_WEEKEND_STYLE1);
            check_text_show();
         }
      }
   }
}

#undef DAYSELECOR_DAY_POS_LEFT
#undef DAYSELECOR_DAY_POS_RIGHT
#undef DAYSELECOR_DAY_POS_MIDDLE
#undef DAYSELECOR_DAY_TYPE_WEEKDAY
#undef DAYSELECOR_DAY_TYPE_WEEKEND_DEFAULT
#undef DAYSELECOR_DAY_TYPE_WEEKEND_STYLE1
#undef DAYSELECOR_DAY_STATE_DEFAULT
#undef DAYSELECOR_DAY_STATE_PRESSED
#undef DAYSELECOR_DAY_STATE_SELECTED
#undef DAYSELECTOR_DAY
